using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuanLyKhachHang.DAO
{
	#region using
	using System.Data;
	using QuanLyKhachHang.DTO;
	#endregion
	public class KH_TIEMNANGDAO : AbstractDAO
	{
		public KH_TIEMNANGDAO(String strPath): base(strPath)
		{
		}

		~KH_TIEMNANGDAO()
		{
			base.Dispose();
		}

		public DataSet SelectAll()
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_KH_TIEMNANG_SelectAll";
				base.FillDataSet(ref ds, "KH_TIEMNANG");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

        public DataSet SelectByID(string stt, int thang, int nam)
        {
            DataSet ds;
            try
            {
                ds = new DataSet();
                base.sql = "usp_KH_TIEMNANG_SelectByID";
                base.InitializeCommand();
                base.AddParameter("@STT", SqlDbType.NVarChar, 100, "TN" + stt);
                base.AddParameter("@THANG", SqlDbType.Int, 100, thang);
                base.AddParameter("@NAM", SqlDbType.Int, 100, nam);
                base.FillDataSet(ref ds, "KH_TIEMNANG");
                return ds;
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            finally
            {
                base.CleanUpObject();
            }
        }

        public bool Insert(KH_CO_SD_TIEMNANGDTO obj, KH_TIEMNANGDTO objtn)
		{
			try
			{
				base.sql = "usp_KH_TIEMNANG_Insert";
				base.InitializeCommand();
                base.AddParameter("@STT", SqlDbType.NVarChar, 100, "TN" + obj.STT);
                base.AddParameter("@MADONVI", SqlDbType.NVarChar, 100, obj.MADONVI);
                base.AddParameter("@THANG", SqlDbType.Int, 100, obj.THANG);
                base.AddParameter("@NAM", SqlDbType.Int, 100, obj.NAM);
                base.AddParameter("@TENKH", SqlDbType.NVarChar, 100, obj.TENKH);
                base.AddParameter("@LOAIHINH", SqlDbType.NVarChar, 100, obj.LOAIHINH);
                base.AddParameter("@NGANH", SqlDbType.NVarChar, 100, obj.NGANH);
                base.AddParameter("@DIACHI", SqlDbType.NVarChar, 100, obj.DIACHI);
                base.AddParameter("@DIENTHOAI", SqlDbType.NVarChar, 100, obj.DIENTHOAI);
                base.AddParameter("@FAX", SqlDbType.NVarChar, 100, obj.FAX);
                base.AddParameter("@NGAYKINIEM", SqlDbType.NVarChar, 100, obj.NGAYKINIEM);
                base.AddParameter("@TENNV", SqlDbType.NVarChar, 100, obj.TENNV);
                base.AddParameter("@NGAYSINHNV", SqlDbType.NVarChar, 100, obj.NGAYSINHNV);
                base.AddParameter("@DIENTHOAINV", SqlDbType.NVarChar, 100, obj.DIENTHOAINV);
                base.AddParameter("@EMAILNV", SqlDbType.NVarChar, 100, obj.EMAILNV);
                base.AddParameter("@DICHVU", SqlDbType.NVarChar, 100, obj.DICHVU);
                base.AddParameter("@SL", SqlDbType.Int, 100, obj.SL);
                base.AddParameter("@DOANHTHU", SqlDbType.BigInt, 100, obj.DOANHTHU);
                base.AddParameter("@DANGSUDUNG", SqlDbType.NVarChar, 100, objtn.DANGSUDUNG);
                base.AddParameter("@LYDO", SqlDbType.NVarChar, 100, objtn.LYDO);
                base.AddParameter("@GHICHU", SqlDbType.NVarChar, 100, objtn.GHICHU);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

        public DataSet SelectByMADONVITHANGNAM(string madonvi, int thang, int nam)
        {
            DataSet ds;
            try
            {
                ds = new DataSet();
                base.sql = "usp_KH_TIEMNANG_SelectByMADONVITHANGNAM";
                base.InitializeCommand();
                base.AddParameter("@MADONVI", SqlDbType.NVarChar, 100, madonvi);
                base.AddParameter("@THANG", SqlDbType.Int, 100, thang);
                base.AddParameter("@NAM", SqlDbType.Int, 100, nam);
                base.FillDataSet(ref ds, "KH_CO_SD");
                return ds;
            }
            catch (System.Exception e)
            {
                throw new Exception(e.Message, e.InnerException);
            }
            finally
            {
                base.CleanUpObject();
            }
        }

		public bool Delete(string stt)
		{
			try
			{
				base.sql = "usp_KH_TIEMNANG_Delete";
				base.InitializeCommand();
                base.AddParameter("@STT", SqlDbType.NVarChar, 100, "TN" + stt);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public bool Update(KH_TIEMNANGDTO obj)
		{
			try
			{
				base.sql = "usp_KH_TIEMNANG_Update";
				base.InitializeCommand();
				base.AddParameter("@STT", SqlDbType.NVarChar, 100, "TN" + obj.STT);
				base.AddParameter("@DANGSUDUNG", SqlDbType.NVarChar, 100, obj.DANGSUDUNG);
				base.AddParameter("@LYDO", SqlDbType.NVarChar, 100, obj.LYDO);
				base.AddParameter("@GHICHU", SqlDbType.NVarChar, 100, obj.GHICHU);
				return ExecuteStoredProcedure();
			}
			catch
			{
				return false;
			}
		}

		public DataSet SelectBySTT(string stt)
		{
			DataSet ds;
			try
			{
				ds = new DataSet();
				base.sql = "usp_KH_TIEMNANG_SelectBySTT";
				base.InitializeCommand();
				base.AddParameter("@STT", SqlDbType.NVarChar, 100, "TN" + stt);
				base.FillDataSet(ref ds, "KH_TIEMNANG");
				return ds;
			}
			catch(System.Exception e)
			{
				throw new Exception(e.Message, e.InnerException);
			}
			finally
			{
				base.CleanUpObject();
			}
		}

	}
}